package com.zwy.ubts.service.impl;

import com.zwy.ubts.bean.Book;
import com.zwy.ubts.bean.User;
import com.zwy.ubts.dao.BookDao;
import com.zwy.ubts.service.BaseService;
import com.zwy.ubts.service.BookService;
import com.zwy.ubts.service.BookTypeService;
import com.zwy.ubts.utils.MybatisUtils;

import java.util.List;

/**
 * @Author Zhou Wenying
 * @Description:
 * @Date Created in 23:36 2023/3/7
 */
public class BookServiceImpl extends BaseService<BookDao> implements BookService {

    private BookTypeService bookTypeService = new BookTypeServiceImpl();
    @Override
    public int addBook(Book book) {
        int i = baseDao.insertBook(book);
        commit();
        return i;
    }

    @Override
    public List<Book> selectHotBook() {
        return baseDao.selectHotBook();
    }

    @Override
    public List<Book> selectNewBook() {
        List<Book> newbooks = baseDao.selectNewBook();
        return newbooks;
    }

    @Override
    public List<Book> selectAllBook(String like) {
        like = "%" + like + "%";
        return baseDao.selectAllBook(like);
    }

    @Override
    public List<Book> selectBookByUserId(Integer userId) {
        return baseDao.selectBookByUserId(userId);
    }

    @Override
    public List<Book> selectBookByCheck() {
        return baseDao.selectBookByCheck();
    }

    @Override
    public Integer deleteBookById(Integer bookId) {
        Integer integer = baseDao.deleteBookById(bookId);
        commit();
        return integer;
    }

    @Override
    public Book selectByBookId(Integer bookId) {
        Book book = baseDao.selectByBookId(bookId);
        if (book == null){
            return null;
        }
        book.setBookType(bookTypeService.queryBookTypeById(Integer.valueOf(book.getBookClassify())));
        return book;
    }

    @Override
    public List<Book> queryBookByClassify(Integer bookClassify,String like) {
        like = "%" + like + "%";
        return baseDao.queryBookByClassify(bookClassify,like);
    }

    @Override
    public Integer updateBookById(Book book) {
        Integer integer = baseDao.updateBookById(book);
        commit();
        return integer;
    }


}
